<template>
  <view class="container">
    <view v-for="(item,index) in examList">
      <uni-card :title="item.title" :is-shadow="true" mode="style" :note="getExamTime(item)"
                @click="onExamClick(item)" :thumbnail="getExamImage(item)">
        <view>题目数：{{ item.question_list.length }}</view>
        <view>总分数：{{ item.totalScore }}</view>
        <view style="color: #f44721;">得分：{{ item.uTotalScore }}</view>
      </uni-card>
    </view>
    <view v-if="examList.length<=0" class="no-data-view" style="color: #777777;">
      <view class="ver-layout-center-all" style="width: fit-content;margin: auto;">
        <image class="no-data-image" src="/static/ic_no_data.jpg"></image>
        <text>暂无考试</text>
      </view>
    </view>
  </view>
</template>

<script>
import {convertDateTime} from "@/common/common.js"
import {examDetail} from "../../router"

export default {
  data() {
    return {
      examList: []
    }
  },
  onLoad() {
    this.getUserExams()
  },
  methods: {
    getUserExams() {
      this.$request('exam/exam/getUserExams', {}).then(res => {
        // debugger
        let result = res.data
        console.log("result", result[0])
        if (result && result.length > 0) {
          this.examList = result
        }
      }).catch(err => {
        // debugger
        uni.showToast({
          title: err.message || "请求失败!"
        })
      })
    },
    getExamImage(item) {
      return item.image ? item.image : require('@/static/exam_banner.jpg')
    },
    getExamTime(item) {
      let start = convertDateTime(item.create_date)
      return `作答时间：${start}`
    },
    onExamClick(examItem) {
      uni.navigateTo({
        url: examDetail + "?examId=" + examItem._id
      })
    },
  }
}
</script>

<style>
.no-data-view {
  position: fixed;
  top: 35vh;
  width: 100%;
  text-align: center;
}

.no-data-image {
  width: 240px;
  height: 100px;
}
</style>
